﻿using System;
using System.ComponentModel.Composition;
using System.Diagnostics.Contracts;

namespace SetVersionNumber.VersionStrategies {

	/// <summary>
	/// Uses the current date as the first three parts of the version number,
	/// and the incrementing build # as the last part of the version number.
	/// </summary>
	[Export(typeof(IVersionStrategy))]
	public class DateAndBuildVersionStrategy : IVersionStrategy {

		/// <summary>
		/// The name of the strategy
		/// </summary>
		public string Name {
			get {
				Contract.Ensures(Contract.Result<string>()==@"date");
				return "date";
			}//get
		}


		/// <summary>
		/// The human-readable description of this strategy
		/// </summary>
		public string Description {
			get {
				const string result = "Uses the current date and increments the existing revision # - yyyy.mm.dd.revision+1";
				Contract.Ensures(Contract.Result<string>() == result);
				return result;
			}//get
		}


		/// <summary>
		/// Get the next version number given the current version number.
		/// </summary>
		/// <param name="currentVersionNumber">The current version number</param>
		/// <returns>The new version number</returns>
		public string GetNextVersionNumber( string currentVersionNumber ) {
			var today = DateTime.Now;
			var version = new Version(currentVersionNumber);
			var newVersion = new Version(today.Year, today.Month, today.Day, version.Revision + 1);
			var result = newVersion.ToString();
			Contract.Assume(!string.IsNullOrWhiteSpace(result));
			return result;
		}

	}//class

}//namespace
